package stack;

import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;


public class p225 {
    public static void main(String[] args) {
        MyStack myStack=new MyStack();
        myStack.push(1);
        myStack.push(2);
        System.out.println(myStack.top());
        System.out.println(myStack.pop());
        System.out.println(myStack.top());
        System.out.println(myStack.empty());
        myStack.pop();
        System.out.println(myStack.empty());

    }

}

class MyStack {
    Queue<Integer> temp;
    Queue<Integer> stack;
    public MyStack() {
        temp=new LinkedList<>();
        stack=new LinkedList<>();
    }

    public void push(int x) {
        if(stack.isEmpty()){
            stack.offer(x);
        }
        else {
            while (!stack.isEmpty()){
                temp.offer(stack.poll());
            }
            stack.offer(x);
            while (!temp.isEmpty()){
                stack.offer(temp.poll());
            }
        }

    }

    public int pop() {
        return stack.poll();
    }

    public int top() {
        return stack.peek();
    }

    public boolean empty() {
        return stack.isEmpty();
    }
}
